define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'custompool/index' + location.search,
                    add_url: 'custompool/add',
                    edit_url: 'custompool/edit',
                    del_url: 'custompool/del',
                    multi_url: 'custompool/multi',
                    import_url: 'custompool/import',
                    table: 'custom',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [

                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'acct_id', title: __('平台'), searchList: Config.adminlist, formatter: Table.api.formatter.normal },
                        {field: 'is_send', title: __('是否分配'), searchList: {"0":__('否'),"1":__('是')}, formatter: Table.api.formatter.status},
                        
                        // {field: 'user_id', title: __('User_id')},
                        { field: 'new_name', title: __('Name'), operate:false },
                        { field: 'name', title: __('Name'), visible: false, operate: 'LIKE' },
                        { field: 'phone', title: __('Phone'), operate: 'LIKE' },
                        { field: 'city', title: __('City'), operate: 'LIKE' },
                        { field: 'address', title: __('Address'), operate: 'LIKE' },
                        { field: 'remark', title: __('备注'), operate: 'LIKE' },
                        { field: 'cate', title: __('客户分类'), operate: 'LIKE' },
                        { field: 'source', title: __('客户来源平台'), operate: 'LIKE' },

                        { field: 'product_cate', title: __('产品类别'), operate: 'LIKE' },
                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        { field: 'user.new_nickname', title: __('销售名称'), operate:false },
                        { field: 'user.nickname', title: __('销售名称'), visible: false, operate: 'LIKE' },
                        { field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE' },
                        // { field: 'jdy_num', title: __('金蝶客户编码'), operate: 'LIKE' },
                        // { field: 'jdy_id', title: __('金蝶ID'), operate: 'LIKE' },
                        
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            });
            $('#distributionButton').on('click', function (row) {
                var ids = Table.api.selectedids(table);
                Fast.api.open('custompool/allocation?ids=' + ids.join(","), '批量分配');
            });

            $('#import').on('click', function (row) {
                Fast.api.open('custompool/import', '批量导入');
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
 
        },
        allocation: function () {
            Controller.api.bindevent();
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        import: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
